
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/07/2011 00:32:30
-- Generated from EDMX file: E:\.Net mvc架构项目\RoRoWoBlog_Src V0.1.50926\RoRoWoBlog\EF.Model\DemoDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DemoDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BLOGARTI_REFERENCE_BLOGCATE]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BlogArticle] DROP CONSTRAINT [FK_BLOGARTI_REFERENCE_BLOGCATE];
GO
IF OBJECT_ID(N'[dbo].[FK_BLOGCOMM_REFERENCE_BLOGARTI]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BlogComment] DROP CONSTRAINT [FK_BLOGCOMM_REFERENCE_BLOGARTI];
GO
IF OBJECT_ID(N'[dbo].[FK_BLOGDIGG_REFERENCE_BLOGARTI]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BlogDigg] DROP CONSTRAINT [FK_BLOGDIGG_REFERENCE_BLOGARTI];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[BlogArticle]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogArticle];
GO
IF OBJECT_ID(N'[dbo].[BlogCategory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogCategory];
GO
IF OBJECT_ID(N'[dbo].[BlogComment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogComment];
GO
IF OBJECT_ID(N'[dbo].[BlogDigg]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogDigg];
GO
IF OBJECT_ID(N'[dbo].[BlogMaster]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogMaster];
GO
IF OBJECT_ID(N'[dbo].[BlogTag]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BlogTag];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'BlogArticle'
CREATE TABLE [dbo].[BlogArticle] (
    [ArticleID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(100)  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [Description] nvarchar(1000)  NULL,
    [ImageUrl] nvarchar(500)  NULL,
    [Tag] nvarchar(4000)  NULL,
    [Hits] int  NOT NULL,
    [IsTop] bit  NOT NULL,
    [State] int  NOT NULL,
    [UserID] int  NULL,
    [UserName] nvarchar(50)  NULL,
    [UserIP] nvarchar(50)  NULL,
    [CreateTime] datetime  NULL,
    [PublishTime] datetime  NULL,
    [UpdateTime] datetime  NULL,
    [Note] nvarchar(400)  NULL,
    [BlogCategory_CateID] int  NOT NULL
);
GO

-- Creating table 'BlogCategory'
CREATE TABLE [dbo].[BlogCategory] (
    [CateID] int IDENTITY(1,1) NOT NULL,
    [CateName] nvarchar(50)  NOT NULL,
    [ParentID] int  NOT NULL,
    [State] int  NOT NULL,
    [SortID] int  NOT NULL,
    [ArticleCount] int  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [Note] nvarchar(400)  NULL
);
GO

-- Creating table 'BlogComment'
CREATE TABLE [dbo].[BlogComment] (
    [AutoID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(50)  NOT NULL,
    [UserID] int  NULL,
    [UserName] nvarchar(50)  NULL,
    [Content] nvarchar(max)  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [IP] nvarchar(50)  NULL,
    [State] int  NOT NULL,
    [VerifyUserID] int  NULL,
    [VerifyUserAccount] nvarchar(50)  NULL,
    [BlogArticle_ArticleID] int  NULL
);
GO

-- Creating table 'BlogDigg'
CREATE TABLE [dbo].[BlogDigg] (
    [AutoID] int IDENTITY(1,1) NOT NULL,
    [DiggName] nvarchar(50)  NULL,
    [SurpportType] int  NOT NULL,
    [State] int  NOT NULL,
    [IP] nvarchar(50)  NULL,
    [CreateTime] datetime  NOT NULL,
    [BlogArticle_ArticleID] int  NULL
);
GO

-- Creating table 'BlogMaster'
CREATE TABLE [dbo].[BlogMaster] (
    [UserID] int IDENTITY(1,1) NOT NULL,
    [UserAccount] nvarchar(50)  NOT NULL,
    [NickName] nvarchar(50)  NULL,
    [UserPassWord] nvarchar(50)  NOT NULL,
    [IsSystem] bit  NOT NULL,
    [State] int  NULL,
    [CreateTime] datetime  NOT NULL,
    [LoginCount] int  NOT NULL,
    [LastLogin] datetime  NOT NULL,
    [Note] nvarchar(200)  NULL
);
GO

-- Creating table 'BlogTag'
CREATE TABLE [dbo].[BlogTag] (
    [TagID] int IDENTITY(1,1) NOT NULL,
    [TagName] nvarchar(50)  NOT NULL,
    [ParentID] int  NOT NULL,
    [State] int  NOT NULL,
    [SortID] int  NOT NULL,
    [ArticleCount] int  NOT NULL,
    [CreateTime] datetime  NOT NULL,
    [Note] nvarchar(400)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ArticleID] in table 'BlogArticle'
ALTER TABLE [dbo].[BlogArticle]
ADD CONSTRAINT [PK_BlogArticle]
    PRIMARY KEY CLUSTERED ([ArticleID] ASC);
GO

-- Creating primary key on [CateID] in table 'BlogCategory'
ALTER TABLE [dbo].[BlogCategory]
ADD CONSTRAINT [PK_BlogCategory]
    PRIMARY KEY CLUSTERED ([CateID] ASC);
GO

-- Creating primary key on [AutoID] in table 'BlogComment'
ALTER TABLE [dbo].[BlogComment]
ADD CONSTRAINT [PK_BlogComment]
    PRIMARY KEY CLUSTERED ([AutoID] ASC);
GO

-- Creating primary key on [AutoID] in table 'BlogDigg'
ALTER TABLE [dbo].[BlogDigg]
ADD CONSTRAINT [PK_BlogDigg]
    PRIMARY KEY CLUSTERED ([AutoID] ASC);
GO

-- Creating primary key on [UserID] in table 'BlogMaster'
ALTER TABLE [dbo].[BlogMaster]
ADD CONSTRAINT [PK_BlogMaster]
    PRIMARY KEY CLUSTERED ([UserID] ASC);
GO

-- Creating primary key on [TagID] in table 'BlogTag'
ALTER TABLE [dbo].[BlogTag]
ADD CONSTRAINT [PK_BlogTag]
    PRIMARY KEY CLUSTERED ([TagID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [BlogCategory_CateID] in table 'BlogArticle'
ALTER TABLE [dbo].[BlogArticle]
ADD CONSTRAINT [FK_BLOGARTI_REFERENCE_BLOGCATE]
    FOREIGN KEY ([BlogCategory_CateID])
    REFERENCES [dbo].[BlogCategory]
        ([CateID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BLOGARTI_REFERENCE_BLOGCATE'
CREATE INDEX [IX_FK_BLOGARTI_REFERENCE_BLOGCATE]
ON [dbo].[BlogArticle]
    ([BlogCategory_CateID]);
GO

-- Creating foreign key on [BlogArticle_ArticleID] in table 'BlogComment'
ALTER TABLE [dbo].[BlogComment]
ADD CONSTRAINT [FK_BLOGCOMM_REFERENCE_BLOGARTI]
    FOREIGN KEY ([BlogArticle_ArticleID])
    REFERENCES [dbo].[BlogArticle]
        ([ArticleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BLOGCOMM_REFERENCE_BLOGARTI'
CREATE INDEX [IX_FK_BLOGCOMM_REFERENCE_BLOGARTI]
ON [dbo].[BlogComment]
    ([BlogArticle_ArticleID]);
GO

-- Creating foreign key on [BlogArticle_ArticleID] in table 'BlogDigg'
ALTER TABLE [dbo].[BlogDigg]
ADD CONSTRAINT [FK_BLOGDIGG_REFERENCE_BLOGARTI]
    FOREIGN KEY ([BlogArticle_ArticleID])
    REFERENCES [dbo].[BlogArticle]
        ([ArticleID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BLOGDIGG_REFERENCE_BLOGARTI'
CREATE INDEX [IX_FK_BLOGDIGG_REFERENCE_BLOGARTI]
ON [dbo].[BlogDigg]
    ([BlogArticle_ArticleID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------